import java.util.ArrayList;
import java.util.List;

/**
 * Measure the network speed in terms of bytes/second; your parameter space
should include the loopback interface card (between 2 processes on the same node),
the TCP protocol stack, UDP, varying packet/buffer size (1B, 1KB, 64KB), and varying the
concurrency (1 thread & 2 threads). The metrics you should be measuring are
throughput (Megabits per second, Mb/sec) and latency (ms)  1*2*3*2 = 12
experiments.

 * @author lucas
 *
 */
public class NetworkBenchmark {
		private Environment _env; 
		
		public NetworkBenchmark(){
			_env = new Environment();
		}
		
		public NetworkBenchmark(Environment env){
			_env = env ;
		}

		public void runTests() {
			
			switch(_env.get_protocol()){
			case 0: // TCP
				runTCPTest();
				break;
			case 1: // UDP
				runUDPTest();
				break;
			}
			
		}

		private void runUDPTest() {
			int nbThread = _env.get_nbThread();
			List<ComputeUDP> tabUDP = new ArrayList<ComputeUDP>();
			
			for(int i=0;i< nbThread;i++){
				//create thread list
				tabUDP.add(new ComputeUDP(_env));
				// start thread List
			}
			
			for(int i=0; i< nbThread; i++){
				tabUDP.get(i).start();
			}

			// join thread List
			for (int i=0; i< nbThread; i++){
				try {
					tabUDP.get(i).join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

		private void runTCPTest() {
			int nbThread = _env.get_nbThread();
			List<ComputeTCP> tabTCP = new ArrayList<ComputeTCP>();
			
			for(int i=0;i< nbThread;i++){
				//create thread list
				tabTCP.add(new ComputeTCP(_env));
			}
			for (int i=0; i<nbThread;i++){
				// start thread List
				tabTCP.get(i).start();
			}
			// join thread List
			for (int i=0; i< nbThread; i++){
				try {
					tabTCP.get(i).join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			
		}
		
		
}
